package com.lz.ht.controller;

import com.lz.ht.model.Increase;
import com.lz.ht.model.Room;
import com.lz.ht.page.PageModel;
import com.lz.ht.result.Result;
import com.lz.ht.service.IncreaseService;
import com.lz.ht.service.RoomAdvanceService;
import com.lz.ht.service.RoomService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @ClassName: IncreaseController
 * @Description:
 * @Author: CHonghao
 * @Date: 2021/7/12 8:24
 * @Version: V1.0
 **/
@Slf4j
@Controller
public class IncreaseController {
    @Autowired
    private IncreaseService increaseServiceImpl;


    @RequestMapping(value = "/increase/list", method = {RequestMethod.GET})
    public String increase_list() throws Exception {
        return "increase/increase_list";
    }


    @RequestMapping(value = "/increase/list", method = {RequestMethod.POST})
    @ResponseBody
    public PageModel increaselist(Increase increase, PageModel<Increase> page) throws Exception {
        page.init();
        List<Increase> list = increaseServiceImpl.findPageList(page, increase);
        long count = increaseServiceImpl.findCount(increase);
        page.packData(count, list);
        return page;
    }

    @RequestMapping(value = "/increase/add", method = {RequestMethod.GET})
    public String addInit(Increase increase, Model model) {
        return "increase/increase_add";
    }

    @RequestMapping(value = "/increase/add", method = {RequestMethod.POST})
    @ResponseBody
    public Result add(Increase increase) {
        increaseServiceImpl.add(increase);
        return Result.genSuccessResult();
    }

    @RequestMapping(value = "/increase/update",method = {RequestMethod.GET})
    public String updateInit(Increase increase, Model model){
        increase = increaseServiceImpl.findById(increase.getIno());
        model.addAttribute("increase",increase);
        return "increase/increase_update";
    }

    @RequestMapping(value = "/increase/update",method = {RequestMethod.POST})
    @ResponseBody
    public Result update(Increase increase){
        increaseServiceImpl.updateById(increase);
        return Result.genSuccessResult();
    }
    @RequestMapping(value = "/increase/delete",method = {RequestMethod.POST})
    @ResponseBody
    public Result delete(Increase increase){
        increaseServiceImpl.deleteById(increase.getIno());
        return Result.genSuccessResult();
    }

}
